package archer.application.elastic.mock.point.api;

import archer.application.elastic.mock.point.entity.UserPoint;
import archer.application.elastic.mock.point.service.UserPointElasticService;
import archer.framework.elastic.controller.BaseElasticController;
import archer.framework.elastic.repository.condition.ElasticCondition;
import archer.framework.protocol.result.ExecuteResult;
import archer.framework.utils.JSONUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


/**
 * @author Terry
 * @dote 2016/7/8
 */
@RestController("elasticUserPointApi")
@RequestMapping("/api/v*/elastic/point/userPoint")
@Transactional
public class UserPointApi extends BaseElasticController {

    @Autowired
    UserPointElasticService userPointElasticService;

    // -----------------------------------------------------
    //                    crud
    // -----------------------------------------------------
    @RequestMapping("store")
    public ExecuteResult store() {
        return userPointElasticService.store();
    }

    @RequestMapping("delete")
    public ExecuteResult delete(String id) {
        return userPointElasticService.delete(id);
    }



    @RequestMapping("deleteAll")
    public ExecuteResult deleteAll() {
        return userPointElasticService.deleteAll();
    }

    // -----------------------------------------------------
    //                    filter context
    // -----------------------------------------------------
    @RequestMapping("findUnique")
    public ExecuteResult findUnique(String id) {
        return userPointElasticService.findUnique(id);
    }

    @RequestMapping("findList")
    public ExecuteResult findList() {
        return userPointElasticService.findList();
    }

    // -----------------------------------------------------
    //                    query context
    // -----------------------------------------------------
    @RequestMapping("all")
    public ExecuteResult all(String queryItem) {
        return userPointElasticService.all();
    }

    @RequestMapping("top")
    public ExecuteResult top(Integer rows, String queryItem) {
        return userPointElasticService.top(rows, asQueryItem(queryItem));
    }

    @RequestMapping("multiTop")
    public ExecuteResult multiTop(Integer rows, String multiMatchItem) {
        return userPointElasticService.multiTop(rows, asMultiMatchItem(multiMatchItem));
    }

    @RequestMapping("findMust")
    public ExecuteResult findMust(String queryItem) {
        return userPointElasticService.findMust(asQueryItem(queryItem));
    }

    @RequestMapping("findMustNot")
    public ExecuteResult findMustNot(String queryItem) {
        return userPointElasticService.findMustNot(asQueryItem(queryItem));
    }

    @RequestMapping("findMultiMatch")
    public ExecuteResult findMultiMatch(String multiMatchItem) {
        return userPointElasticService.findMultiMatch(asMultiMatchItem(multiMatchItem));
    }

    @RequestMapping("findTextList")
    public ExecuteResult findTextList() {
        return userPointElasticService.findTextList();
    }

    // -----------------------------------------------------
    //                    ElasticCondition
    // -----------------------------------------------------
    @RequestMapping("findElasticPagedList")
    public ExecuteResult findElasticPagedList(String elasticCondition) {
        return userPointElasticService.findElasticPagedList((ElasticCondition) JSONUtils.deserialize(elasticCondition, ElasticCondition.class));
    }

    // -----------------------------------------------------
    //                    docStore操作
    // -----------------------------------------------------

    @RequestMapping("indexByQuery")
    public ExecuteResult indexByQuery() {
        return userPointElasticService.indexByQuery(UserPoint.find.query());
    }

    @RequestMapping("indexByQuerySize")
    public ExecuteResult indexByQuerySize(Integer bulkSize) {
        return userPointElasticService.indexByQuery(UserPoint.find.query(), bulkSize);
    }

    @RequestMapping("indexAll")
    public ExecuteResult indexAll() {
        return userPointElasticService.indexByQuery(UserPoint.find.query());
    }

    @RequestMapping("dropIndex")
    public ExecuteResult dropIndex(String indexName) {
        return userPointElasticService.dropIndex(indexName);
    }

}
